package com.ruoyi.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Refund;
import com.ruoyi.system.service.IRefundService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 还款Controller
 * 
 * @author ruoyi
 * @date 2021-09-27
 */
@RestController
@RequestMapping("/system/refund")
public class RefundController extends BaseController
{
    @Autowired
    private IRefundService refundService;

    /**
     * 查询还款列表
     */
    @PreAuthorize("@ss.hasPermi('system:refund:list')")
    @GetMapping("/list")
    public TableDataInfo list(Refund refund)
    {
        startPage();
        List<Refund> list = refundService.selectRefundList(refund);
        return getDataTable(list);
    }

    /**
     * 导出还款列表
     */
    @PreAuthorize("@ss.hasPermi('system:refund:export')")
    @Log(title = "还款", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Refund refund)
    {
        List<Refund> list = refundService.selectRefundList(refund);
        ExcelUtil<Refund> util = new ExcelUtil<Refund>(Refund.class);
        return util.exportExcel(list, "还款数据");
    }

    /**
     * 获取还款详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:refund:query')")
    @GetMapping(value = "/{refId}")
    public AjaxResult getInfo(@PathVariable("refId") Long refId)
    {
        return AjaxResult.success(refundService.selectRefundByRefId(refId));
    }

    /**
     * 新增还款
     */
    @PreAuthorize("@ss.hasPermi('system:refund:add')")
    @Log(title = "还款", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Refund refund)
    {
        return toAjax(refundService.insertRefund(refund));
    }

    /**
     * 修改还款
     */
    @PreAuthorize("@ss.hasPermi('system:refund:edit')")
    @Log(title = "还款", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Refund refund)
    {
        return toAjax(refundService.updateRefund(refund));
    }

    /**
     * 删除还款
     */
    @PreAuthorize("@ss.hasPermi('system:refund:remove')")
    @Log(title = "还款", businessType = BusinessType.DELETE)
	@DeleteMapping("/{refIds}")
    public AjaxResult remove(@PathVariable Long[] refIds)
    {
        return toAjax(refundService.deleteRefundByRefIds(refIds));
    }
}
